package com.yq.tanhua.ui.chat.conversationlist

import androidx.lifecycle.viewModelScope
import com.blankj.utilcode.util.ToastUtils
import com.fmt.mvi.learn.gobal.log
import com.hyphenate.chat.EMConversation
import com.yq.tanhua.net.BaseViewModel
import com.yq.tanhua.im.ImFunction
import dagger.hilt.android.lifecycle.HiltViewModel
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.launch
import java.util.Objects
import javax.inject.Inject
import kotlin.jvm.internal.Intrinsics.Kotlin


@HiltViewModel
open class ConversationViewMode @Inject constructor() : BaseViewModel() {

    @Inject
    lateinit var imFunction: ImFunction

    val conversationViewUIData = MutableStateFlow(ConversationViewUIData(null))


    fun getConversionListData() {
        imFunction.testhilt()
        viewModelScope.launch {
            kotlin.runCatching {
                val allConversations = imFunction.getAllConversations()
                conversationViewUIData.value =
                    conversationViewUIData.value.copy(conversationDatas = allConversations)
            }.onFailure {
                it.printStackTrace()
                it.log()
                ToastUtils.showShort(it.message)
                conversationViewUIData.value =
                    conversationViewUIData.value.copy(conversationDatas = null)
            }

        }

    }
}

data class ConversationViewUIData(var conversationDatas: MutableMap<String, EMConversation>?)